<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>客户界面</title>
<script type="text/javascript" src="jquery-1.9.0.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		$("#btn").click(function() {
			var parentName = $("#parentName").val();
			if (parentName == "") {
				alert("父亲名称不能为空");
				return;
			}
			$("#selParentId").empty();
			$.ajax({
				url : "${pageContext.request.contextPath }/customAjax/listparent.action",
				type : "get",
				dataType : "json",
				data : {//请求携带参数
				customName : parentName
				},
				success : function(data) {
					//请求成功后做什么，请写上你的代码
					//data返回的数据
					var obj = data;
					var str = obj.result;
					//var obj1 = eval('(' + str + ')');
					//此方法测试中失败
					//var obj2 = str.parseJSON(); //由JSON字符串转换为JSON对象，，
					var obj3 = JSON.parse(str); //由JSON字符串转换为JSON对象

					for ( var i in obj3) {
						var id = obj3[i].id;
						$("#selParentId").append('<option value="' + id + '">'
							+ id + "-" + obj3[i].cusName + obj3[i].birthday
							+ '</option>');
					}

				},
				error : function() {
					alert('执行失败');
				}
			});
		});
	});

	function check(){
		var id = $("input[name='entity.id']").val()
		if(typeof(id) == "undefined"|| id==null || id ==""){
			//$("p").hide();
		  	//$("p").show();
			$("#divid").show();
		}
		
		return false;
	}
	
	function checkId(){
		var id = $("input[name='entity.id']").val()
		if(typeof(id) == "undefined"|| id==null || id ==""){
			$("#divid").show();
		}else{
			$("#divid").hide();
		}
	}
	
	function checkByEle(ele){
		alert(1);
		ele.getText;
		var id = ele.val()
		if(typeof(id) == "undefined"|| id==null || id ==""){
			$("#divid").show();
		}else{
			$("#divid").hide();
		}
	}
</script>
</head>
<body>
	<div style="width: 700px; margin: 0 auto">
		<div id="div1" align="left"
			style="position: absolute; width: 400px; height: 500px; background: #ff55ff; left: 0px; top: 0px">
			<p>请注册输入个人信息</p>
			<form id="myform" name="myform" onsubmit="return check()"
				action="${pageContext.request.contextPath }/custom/save.action">
				<table>
					<tr>
						<td><div id="divid" style="color: red;border: 1px dashed red;display: none">个人ID不能为空</div></td>
					</tr>
					<tr>
						<td>个人ID：</td>
						<td><input type="text" name="entity.id" onblur="checkByEle(this)"/></td>
					</tr>
					<tr>
						<td>姓名：</td>
						<td><input type="text" name="entity.cusName" /></td>
					</tr>
					<tr>
						<td>密码：</td>
						<td><input type="password" name="entity.pwd" /></td>
					</tr>
					<tr>
						<td>别名：</td>
						<td><input type="text" name="entity.othName" /></td>
					</tr>
					<tr>
						<td>性别:</td>
						<td><input type="radio" name="entity.cusSex" value="1"
							checked="checked" />男&nbsp;&nbsp;&nbsp;&nbsp; <input
							type="radio" name="entity.cusSex" value="0" />女</td>
					</tr>
					<tr>
						<td>是否在世</td>
						<td><input type="radio" name="entity.isLive" value="1"
							checked="checked" />是&nbsp;&nbsp;&nbsp;&nbsp; <input
							type="radio" name="entity.isLive" value="0" />否</td>
					</tr>
					<tr>
						<td>生日：</td>
						<td><input type="text" name="entity.birthday" /></td>
					</tr>
					<tr>
						<td>现居住地址：</td>
						<td><input type="text" name="entity.nowAdrr" /></td>
					</tr>
					<tr>
						<td>祖籍地址：</td>
						<td><input type="text" name="entity.nowAdrr" /></td>
					</tr>
					<tr>
						<td>现居城市：</td>
						<td><input type="text" name="entity.nowAdrr" /></td>
					</tr>
					<tr>
						<td>父亲：</td>
						<td><input type="text" name="parentName" id="parentName" />
							<input type="hidden" id="id" /></td>
					</tr>
					<tr>
						<td><input type="button" value="查询" id="btn"></td>
						<td><select id="selParentId"></select></td>
					</tr>
					<tr>
						<td><input type="submit" value="提交" /></td>
						<td></td>
					</tr>
				</table>
			</form>
		</div>

		<div id="div2"
			style="position: absolute; left: 404px; top: 0px; border: solid 1px #0000FF; width: 800px; height: 500px">
			<p>错误提示：</p>
			<p id="error"></p>
		</div>

	</div>

</body>
</html>